package com.itheima.postprocess;

import com.itheima.pojo.PaperBox;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @author huyoufu <https://github.com/huyoufu>
 * @TIME 2020-08-07 09:50
 * @description
 */
 //对象后置处理器
public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return null;
    }
    /**
     *  这个方法是在spring框架 把对象创建好以后 才会调用!!!
     *
     * @param bean 是默认帮你创建的对象
     * @param beanName 创建好对象的名字
     * @return     你想要替换的对象
     * @throws BeansException
     */
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        System.out.println("我是质检员!!!!来康康你们!!");
        System.out.println("正在查看:"+bean);
        if (bean instanceof PaperBox){
            //强转嘛!!!
            PaperBox modifiedPaperBox= (PaperBox) bean;
            modifiedPaperBox.setLogo("心心相映");
            return  modifiedPaperBox;
        }

        return null;
    }
}
